package com.example.app2;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class MyAdapter extends ArrayAdapter {


    public MyAdapter(@NonNull Context context, int resource, @NonNull ArrayList<HashMap<String,String>> list) {
        super(context, resource, list);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = convertView;
        if(view == null){
            view = LayoutInflater.from(getContext()).inflate(R.layout.listitem_map,parent,false);
        }       //获取需要的适配器布局，   得到适配器的基本形式

        Map<String,String> map = (Map<String, String>) getItem(position);  //传入的数据
        TextView coin = (TextView) view.findViewById(R.id.coin);           //获得布局中的控件
        TextView rate = (TextView) view.findViewById(R.id.rate);

        coin.setText("M:" + map.get("coin"));           //适配器展现
        rate.setText("R:" + map.get("rate"));

        return view;
    }




}
